home *** CD-ROM | disk | FTP | other *** search
/ PC Format (PL) 2008 February / PC_Format_022008.iso / Internet / Mozilla Thunderbird wtyczki / lightning-0.7-tb-win.xpi / chrome / lightning.jar / content / lightning / lightning-utils.js < prev    next >
Encoding:
JavaScript  |  2006-08-21  |  3.9 KB  |  110 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is Lightning code.
  15.  *
  16.  * The Initial Developer of the Original Code is Oracle Corporation
  17.  * Portions created by the Initial Developer are Copyright (C) 2005
  18.  * the Initial Developer. All Rights Reserved.
  19.  *
  20.  * Contributor(s):
  21.  *   Vladimir Vukicevic <vladimir@pobox.com>
  22.  *   Mike Shaver <shaver@mozilla.org>
  23.  *   Joey Minta <jminta@gmail.com>
  24.  *
  25.  * Alternatively, the contents of this file may be used under the terms of
  26.  * either the GNU General Public License Version 2 or later (the "GPL"), or 
  27.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28.  * in which case the provisions of the GPL or the LGPL are applicable instead
  29.  * of those above. If you wish to allow use of your version of this file only
  30.  * under the terms of either the GPL or the LGPL, and not to allow others to
  31.  * use your version of this file under the terms of the MPL, indicate your
  32.  * decision by deleting the provisions above and replace them with the notice
  33.  * and other provisions required by the GPL or the LGPL. If you do not delete
  34.  * the provisions above, a recipient may use your version of this file under
  35.  * the terms of any one of the MPL, the GPL or the LGPL.
  36.  *
  37.  * ***** END LICENSE BLOCK ***** */
  38.  
  39. function ltnCreateInstance(cid, iface) {
  40.     if (!iface)
  41.         iface = "nsISupports";
  42.     try {
  43.         return Components.classes[cid].createInstance(Components.interfaces[iface]);
  44.     } catch(e) {
  45.         dump("#### ltnCreateInstance failed for: " + cid + "\n");
  46.         var frame = Components.stack;
  47.         for (var i = 0; frame && (i < 4); i++) {
  48.             dump(i + ": " + frame + "\n");
  49.             frame = frame.caller;
  50.         }
  51.         throw e;
  52.     }
  53. }
  54.  
  55. function ltnGetService(cid, iface) {
  56.     if (!iface)
  57.         iface = "nsISupports";
  58.     try {
  59.         return Components.classes[cid].getService(Components.interfaces[iface]);
  60.     } catch(e) {
  61.         dump("#### ltnGetService failed for: " + cid + "\n");
  62.         var frame = Components.stack;
  63.         for (var i = 0; frame && (i < 4); i++) {
  64.             dump(i + ": " + frame + "\n");
  65.             frame = frame.caller;
  66.         }
  67.         throw e;
  68.     }
  69. }
  70.  
  71. var atomSvc;
  72. function ltnGetAtom(str) {
  73.     if (!atomSvc) {
  74.         atomSvc = ltnGetService("@mozilla.org/atom-service;1", "nsIAtomService");
  75.     }
  76.  
  77.     return atomSvc.getAtom(str);
  78. }
  79.  
  80. var CalDateTime = new Components.Constructor("@mozilla.org/calendar/datetime;1",
  81.                                              Components.interfaces.calIDateTime);
  82.  
  83. // Use these functions, since setting |element.collapsed = true| is NOT reliable
  84. function collapseElement(element) {
  85.     element.style.visibility = "collapse";
  86. }
  87.  
  88. function uncollapseElement(element) {
  89.     element.style.visibility = "";
  90. }
  91.  
  92. function updateUndoRedoMenu() {
  93.     //XXX give Lightning some undo/redo UI!
  94. }
  95.  
  96. /**
  97.  * Gets the value of a string in a .properties file
  98.  *
  99.  * @param aBundleName  the name of the properties file.  It is assumed that the
  100.  *                     file lives in chrome://lightning/locale/
  101.  * @param aStringName the name of the string within the properties file
  102.  */
  103. function ltnGetString(aBundleName, aStringName)
  104. {
  105.     var sbs = Components.classes["@mozilla.org/intl/stringbundle;1"]
  106.                         .getService(Components.interfaces.nsIStringBundleService);
  107.     var props = sbs.createBundle("chrome://lightning/locale/"+aBundleName+".properties");
  108.     return props.GetStringFromName(aStringName);
  109. }
  110.